import request from '@/utils/request';

// 用户管理API
export function getAllUsers() {
    return request({
        url: '/user/admin/users',
        method: 'get'
    });
}

export function addUser(userInfo) {
    return request({
        url: '/user/register',
        method: 'post',
        data: userInfo
    });
}

export function updateUser(userInfo) {
    return request({
        url: `/user/${userInfo.userId}`,
        method: 'put',
        data: userInfo
    });
}

export function deleteUser(userId) {
    return request({
        url: `/user/${userId}`,
        method: 'delete'
    });
}

export function updateUserStatus(userId, status) {
    return request({
        url: `/user/${userId}/status`,
        method: 'put',
        params: { status }
    });
}

// 商品管理API
export function getAllProducts() {
    return request({
        url: '/products',
        method: 'get'
    });
}

export function getProductById(productId) {
    return request({
        url: `/products/${productId}`,
        method: 'get'
    });
}

export function addProduct(product) {
    return request({
        url: '/products',
        method: 'post',
        data: product
    });
}

export function updateProduct(product) {
    return request({
        url: '/products',
        method: 'put',
        data: product
    });
}

export function deleteProduct(productId) {
    return request({
        url: `/products/${productId}`,
        method: 'delete'
    });
}

export function searchProducts(params) {
    return request({
        url: '/products/search/advanced',
        method: 'get',
        params
    });
}

// 商品状态切换API
export function toggleProductStatus(productId, status) {
    return request({
        url: `/products/${productId}/status`,
        method: 'put',
        params: { status }
    });
}

export function toggleHotStatus(productId, isHot) {
    return request({
        url: `/products/${productId}/hot`,
        method: 'put',
        params: { isHot }
    });
}

// 订单管理API
export function getAllOrders() {
    return request({
        url: '/order/all',
        method: 'get'
    });
}

export function getOrderById(orderId) {
    return request({
        url: `/order/${orderId}`,
        method: 'get'
    });
}

export function getOrderDetails(orderId) {
    return request({
        url: `/order-detail/${orderId}`,
        method: 'get'
    });
}

export function updateOrder(order) {
    return request({
        url: '/order',
        method: 'put',
        data: order
    });
}

// 分类管理API
export function getAllCategories() {
    return request({
        url: '/categories',
        method: 'get'
    });
}

export function addCategory(category) {
    return request({
        url: '/categories',
        method: 'post',
        data: category
    });
}

export function updateCategory(category) {
    return request({
        url: '/categories',
        method: 'put',
        data: category
    });
}

export function deleteCategory(categoryId) {
    return request({
        url: `/categories/${categoryId}`,
        method: 'delete'
    });
}

export function searchCategoriesByName(name) {
    return request({
        url: '/categories/search',
        method: 'get',
        params: { name }
    });
}